
ObjStateMode = {
	Wireframe = function ()
		TRACE("ObjStateMode - Wireframe called.\n")
		for _,o in ipairs(SelectMode.PickObjs) do
			o:SetShowWireframe(not o:GetShowWireframe())
		end
	end,
	Vertex = function ()
		TRACE("ObjStateMode - Vertex called.\n")
		for _,o in ipairs(SelectMode.PickObjs) do
			o:SetShowVertex(not o:GetShowVertex())
		end
	end,
	CullNone = function ()
		TRACE("ObjStateMode - CullNone called.\n")
		for _,o in ipairs(SelectMode.PickObjs) do
			o:SetCullNone(not o:GetCullNone())
		end
	end,
	AlphaBlend = function ()
		TRACE("ObjStateMode - AlphaBlend called.\n")
		for _,o in ipairs(SelectMode.PickObjs) do
			o:SetAlphaBlend(not o:GetAlphaBlend())
		end
	end,
	AlphaTest = function ()
		TRACE("ObjStateMode - AlphaTest called.\n")
		for _,o in ipairs(SelectMode.PickObjs) do
			o:SetAlphaTest(not o:GetAlphaTest())
		end
	end,
	Group = function ()
		TRACE("ObjStateMode - Group called\n")
		local Num = table.getn(SelectMode.PickObjs)
		if Num<=1 then
			TRACE("Group - should select more than 2 objs!\n")
			return
		end
		local MainObj = SelectMode.PickObjs[1]
		for i=2,Num do
			MainObj:AddObj(SelectMode.PickObjs[i]:GetName())
		end
		SelectMode.ClearObj()
		SelectMode.AddObj(MainObj)
	end,
	Remove = function ()
		TRACE("ObjStateMode - Remove called.\n")
		for _,o in ipairs(SelectMode.PickObjs) do
			local ObjName = o:GetName()
			TRACE(string.format("ObjStateMode - Removing %s\n",ObjName))
			g_MgrObj:Remove(ObjName)
		end
		SelectMode.PickObjs = {}
	end,
	Combine = function ()
		TRACE("ObjStateMode - Combine called\n")
		local num = table.getn(SelectMode.PickObjs)
		if num<=1 then
			TRACE("ObjStateMode - less than 2 objs\n")
			return
		end
		local FinalObj = SelectMode.PickObjs[1]
		local FinalPos = FinalObj:GetPos()
		local FinalMeshName = FinalObj:GetMesh()
		local FinalMesh = g_MgrMesh:Find(FinalMeshName)
		if not FinalMesh then
			TRACE("ObjStateMode - Invalid mesh!\n")
			return
		end
		FinalMesh:Scale(FinalObj:GetScaling())
		FinalObj:SetScaling({x=1,y=1,z=1})
		for i=2,num do
			local CurObj = SelectMode.PickObjs[i]
			local CurMeshName = CurObj:GetMesh()
			local CurMesh = g_MgrMesh:Find(CurMeshName)
			local CurPos = CurObj:GetPos()
			local PosBias = {x=CurPos.x-FinalPos.x,y=CurPos.y-FinalPos.y,z=CurPos.z-FinalPos.z}
			if CurMesh then
				CurMesh:Scale(CurObj:GetScaling())
				CurMesh:Translation(PosBias)
				g_MgrObj:Remove(CurObj:GetName())
				g_MgrMesh:Combine(FinalMeshName,CurMeshName,FinalMeshName)
			else
				TRACE("ObjStateMode - Invalid mesh skipped!\n")
			end
		end
		FinalObj:SetupBounding()
		SelectMode.PickObjs = {}
	end,
	ComputeNormal = function ()
		for _,o in ipairs(SelectMode.PickObjs) do
			local MeshName = o:GetMesh()
			local Mesh = g_MgrMesh:Find(MeshName)
			if Mesh then
				Mesh:ComputeNormal()
			end
		end
	end,
	Light = function ()
		for _,o in ipairs(SelectMode.PickObjs) do
			o:SetLightEnable(not o:GetLightEnable())
		end
	end
}
